*Replicates main tables in paper. Note, to run one table at a time, you must run the entire block of code for a given table at once.

*************************************************************
*Table 1: Summary Statistics - Treatment and Control Comparisons (1990 Variables)
*Last row requires restricted CDC data. 
************************************************************
use "$tmp/final_playonly.dta", clear

* Generate top quartile indicator and its complement
cap gen tquartile0 = tquartile1==0
cap file close sumstat
file open sumstat using "$out/Table1.txt", write replace
file write sumstat "Variable" _tab "Top-Quartile County"  _tab "Other Shale Play County" _tab "Within Play Difference" _n
file write sumstat _tab "(1)" _tab "(2)" _tab "(3)" _n 
*High School Graduates
	file write sumstat "% High School Graduates"
	reg pcthighschool1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])
	
	reghdfe pcthighschool1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pcthighschool1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pcthighschool1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n
	
*Manufacturing
	file write sumstat "% in Manufacturing"
	reg pctmanufacturing1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])
	
	reghdfe pctmanufacturing1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctmanufacturing1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctmanufacturing1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*White
	file write sumstat "% White"
	reg pctwhite11990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])
	
	reghdfe pctwhite11990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctwhite11990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctwhite11990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*Married
	file write sumstat "% Married"
	reg pctmarried1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])

	reghdfe pctmarried1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctmarried1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctmarried1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*Rural
	file write sumstat "% Rural"
	reg pctrural1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])

	reghdfe pctrural1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctrural1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctrural1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*Veterans
	file write sumstat "% Veterans"
	reg pctveteran1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])

	reghdfe pctveteran1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctveteran1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctveteran1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*Foreign Born
	file write sumstat "% Foreign Born"
	reg pctforeignborn1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])

	reghdfe pctforeignborn1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctforeignborn1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctforeignborn1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*Bachelors Degree
	file write sumstat "% w/ a Bachelors Degree"
	reg pctbachelors1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])
	
	reghdfe pctbachelors1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum pctbachelors1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum pctbachelors1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

*Household Income
	file write sumstat "Median Household Income"
	reg medianhhinc1990 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])
	
	reghdfe medianhhinc1990 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum medianhhinc1990 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum medianhhinc1990 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n


*Death Rate
	file write sumstat "Age-Adjusted Death Rate"
	reg adr2000dc0_gen0_eth00 tquartile0 tquartile1 if year == 1990 , nocons
	file write sumstat _tab %9.2f (_b[tquartile1]) _tab %9.2f (_b[tquartile0])
	
	reghdfe adr2000dc0_gen0_eth00 tquartile0 if year == 1990 , a(splay1) vce(robust)
	file write sumstat _tab %9.2f (_b[tquartile0])
	test tquartile0 = 0
	loc p = r(p)
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p'>=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p'>=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat _n
	
	* Add standard deviations and standard error
	qui sum adr2000dc0_gen0_eth00 if tquartile1==1 & year == 1990
	loc sd_tq1 = r(sd)
	qui sum adr2000dc0_gen0_eth00 if tquartile0==1 & year == 1990
	loc sd_tq0 = r(sd)
	loc se_reg = _se[tquartile0]
	file write sumstat _tab "(" %5.2f (`sd_tq1') ")" _tab "(" %5.2f (`sd_tq0') ")" _tab "[" %5.2f (`se_reg') "]" _n

qui count if tquartile0 == 1  & year == 1990
loc ncont = r(N)
qui count if tquartile1 == 1  & year == 1990
loc ntreat = r(N)
file write sumstat "Observations" _tab %7.0f (`ntreat') _tab %7.0f (`ncont') _tab %7.0f (`ntreat' + `ncont') _n
file close sumstat


*************************************************************
*Table 2: Working-Age Overall Mortality Rates by Gender
**Requires Restricted CDC Mortality Data
**Variable naming in code (See readme for more details)
**cdrdc0_gen0_eth00_a2564, crude overall death rate (dc0), both genders (gen0)
**cdrdc0_gen1_eth00_a2564, crude overall death rate (dc0), male (gen1)
**cdrdc0_gen2_eth00_a2564, crude overall death rate (dc0), female (gen2)
************************************************************
use "$tmp/final_playonly.dta", clear
forval i = 0/2 {
loc panel = cond(`i'==0, "A",cond(`i'==1,"B","C"))
loc panelheader = cond(`i'==0, "Panel A: Overall",cond(`i'==1,"Panel B: Men","Panel C: Women"))

*no controls
qui reghdfe cdrdc0_gen`i'_eth00_a2564  ddtquartile1   $main
qui su cdrdc0_gen`i'_eth00_a2564 if e(sample)==1
loc ymean: di %9.2f r(mean)
outreg2 using "$out/Table2`panel'", tex(pretty) replace keep(ddtquartile1) ///
  	addtext(Controls,NO,"Outcome Mean", `ymean')  label nocons title("`panelheader'") ///
	bdec(3) sdec(4) bfmt(fc) se bracket nonotes
	    
*add economic
qui reghdfe cdrdc0_gen`i'_eth00_a2564  ddtquartile1 c.pcthighschool1990#i.year  c.pctwhite11990#i.year c.pctmanufacturing1990#i.year $main
qui su cdrdc0_gen`i'_eth00_a2564 if e(sample)==1
loc ymean: di %9.2f r(mean)

outreg2 using "$out/Table2`panel'", tex(pretty) append keep(ddtquartile1) ///
  	addtext(Controls,"Base","Outcome Mean", `ymean')  label nocons ///
	bdec(3) sdec(4) bfmt(fc) se bracket nonotes

*add demogrpahic
qui reghdfe cdrdc0_gen`i'_eth00_a2564  ddtquartile1 $rhs $main
qui su cdrdc0_gen`i'_eth00_a2564 if e(sample)==1
loc ymean: di %9.2f r(mean)

outreg2 using "$out/Table2`panel'", tex(pretty) append keep(ddtquartile1) ///
  	addtext(Controls,"All","Outcome Mean", `ymean')  label nocons ///
	bdec(3) sdec(4) bfmt(fc) se bracket nonotes

	}
	
	
*************************************************************
*Table 3: Health Insurance Coverage by Gender: Ages 18-64
*************************************************************
use "$tmp\SAHIE",replace
//Overall (gen0)
reghdfe PCTIC_pall_gen0 ddtquartile1 $rhs, absorb(splay1_year_fe cntyfips2000) vce(cl cntyfips2000)
qui su PCTIC_pall_gen0 if e(sample)==1
loc ymean: di %9.2f r(mean)
outreg2 using "$out/Table3", tex(pretty) replace keep(ddtquartile1) ///
  	addtext(Controls,All,"Outcome Mean", `ymean')  label nocons ///
	ctitle("Overall") ///
	bdec(3) sdec(4) bfmt(fc) se bracket nor2 nonotes

// Run second regression (Men/gen1) 
reghdfe PCTIC_pall_gen1 ddtquartile1 $rhs, absorb(splay1_year_fe cntyfips2000) vce(cl cntyfips2000)
qui su PCTIC_pall_gen1 if e(sample)==1
loc ymean: di %9.2f r(mean)
outreg2 using "$out/Table3", tex(pretty) append keep(ddtquartile1) ///
  	addtext(Controls,All,"Outcome Mean", `ymean')  label nocons ///
	ctitle("Men") ///
	bdec(3) sdec(4) bfmt(fc) se bracket nor2 nonotes

// Run third regression (Women/gen2)
reghdfe PCTIC_pall_gen2 ddtquartile1 $rhs, absorb(splay1_year_fe cntyfips2000) vce(cl cntyfips2000)
qui su PCTIC_pall_gen2 if e(sample)==1
loc ymean: di %9.2f r(mean)
outreg2 using "$out/Table3", tex(pretty) append keep(ddtquartile1) ///
  	addtext(Controls,All,"Outcome Mean", `ymean')  label nocons ///
	ctitle("Women") ///
	bdec(3) sdec(4) bfmt(fc) se bracket nor2 nonotes

